package com.maxmlr.nacosclient.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 通过RestTemplate实现接口调用
 *
 * @author maxiao
 * @create 2019/5/18
 * @since 1.0.0
 */
@RestController
public class TestRestController {


    @Autowired
    RestTemplate restTemplate;


    @GetMapping("/test_rest")
    public String test() {
        String result = restTemplate.getForObject("http://nacos-server/echo/test_rest", String.class);
        return "return : " + result;
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }


}
